<template>
  <div class="step-progress">
    <div class="progress-bar-container">
      <div 
        class="progress-bar" 
        :style="{ width: progressWidth }"
      ></div>
    </div>
    <div class="steps-container">
      <div 
        v-for="(step, index) in steps" 
        :key="index"
        class="step-item"
        :class="{ active: index <= current, completed: index < current }"
      >
        <div class="step-icon">
          <el-icon v-if="index < current">
            <Check />
          </el-icon>
          <span v-else>{{ index + 1 }}</span>
        </div>
        <div class="step-text">{{ step }}</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { ElIcon } from 'element-plus'
import { Check } from '@element-plus/icons-vue'

const props = defineProps({
  steps: {
    type: Array,
    required: true,
    default: () => []
  },
  current: {
    type: Number,
    default: 0
  }
})

const progressWidth = computed(() => {
  if (props.steps.length <= 1) return '0%'
  const percentage = (props.current / (props.steps.length - 1)) * 100
  return `${Math.min(percentage, 100)}%`
})
</script>

<style scoped>
.step-progress {
  width: 100%;
}

.progress-bar-container {
  height: 4px;
  background-color: #e4e7ed;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 30px;
  position: relative;
}

.progress-bar {
  height: 100%;
  background-color: #409eff;
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0;
}

.steps-container {
  display: flex;
  justify-content: space-between;
}

.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  position: relative;
}

.step-item:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 16px;
  left: 50%;
  right: -50%;
  height: 2px;
  background-color: #e4e7ed;
  z-index: 1;
}

.step-item.active:not(:last-child)::after {
  background-color: #409eff;
}

.step-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: #e4e7ed;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c0c4cc;
  font-size: 14px;
  font-weight: bold;
  z-index: 2;
  transition: all 0.3s ease;
  margin-bottom: 8px;
}

.step-item.active .step-icon {
  background-color: #409eff;
  color: #fff;
  border-color: #409eff;
}

.step-item.completed .step-icon {
  background-color: #67c23a;
  color: #fff;
  border-color: #67c23a;
}

.step-text {
  font-size: 14px;
  color: #909399;
  transition: color 0.3s ease;
}

.step-item.active .step-text {
  color: #409eff;
  font-weight: 500;
}

.step-item.completed .step-text {
  color: #67c23a;
}
</style>